/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.uff.pgci.sgca.gateway.client;

import br.uff.pgci.sgca.gateway.model.Mensagem;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jboss.netty.channel.ChannelEvent;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.jboss.netty.channel.UpstreamMessageEvent;

/**
 *
 * @author anapaula
 */
public class ProcessadosDeMensagemDeRetornoHandler extends SimpleChannelUpstreamHandler {

    private static final Logger logger = Logger.getLogger(ProcessadosDeMensagemDeRetornoHandler.class.getName());
    
    @Override
    public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
//        super.handleUpstream(ctx, e);
        if (e instanceof UpstreamMessageEvent) {
            String retorno = (String) ((UpstreamMessageEvent) e).getMessage();
            logger.log(Level.INFO, "Mensagem recebida de retorno:{0}", retorno);
        }
    }

    public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
            throws Exception {
        e.getCause().printStackTrace();
        e.getChannel().close();
    }
}
